home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_325 / dclock / dclock.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  30KB  |  1,331 lines

  1. /* DClock.c *****************************************************************
  2. *
  3. *    DClock --------    A Dumb Clock utility, my idea of how a clock
  4. *            should really be like.
  5. *
  6. *    Author --------    Olaf 'Olsen' Barthel, MXM
  7. *            Brabeckstrasse 35
  8. *            D-3000 Hannover 71
  9. *
  10. *            Federal Republic of Germany
  11. *
  12. *    This  program  truly is in the PUBLIC DOMAIN.  Written on a cold
  13. *    and  damp  September  evening,  hoping the next morning would be
  14. *    better.
  15. *
  16. *    Compiled using Aztec C 3.6a, CygnusEd Professional 2 & ARexx.
  17. *
  18. ****************************************************************************/
  19.  
  20.     /* These belong to ARP. */
  21.  
  22. #include <intuition/intuitionbase.h>
  23. #include <libraries/arpbase.h>
  24. #include <graphics/gfxbase.h>
  25. #include <arpfunctions.h>
  26.  
  27. #include "DClock.h"
  28.  
  29.     /* ARP help messages. */
  30.  
  31. char *CLI_Template    = "QUIT/S,INFO/S,BEEP/K,CLICK/K,CLICKVOLUME/K,PRIORITY/K,TEXTCOLOUR/K,BACKCOLOUR/K,ALARM/K,ALARMTIME/K,QUIET/S,REFRESH/S,SETENV/K";
  32. char *CLI_Help        = "\nUsage: \33[1mDClock\33[0m [QUIT] [INFO] [BEEP ON|OFF] [CLICK ON|OFF] [CLICKVOLUME 0-64]\
  33. \n              [PRIORITY -127 - 127] [TEXTCOLOUR #] [BACKCOLOUR #] [QUIET]\n              [ALARM ON|OFF|INFO] [ALARMTIME HH:MM:SS] [REFRESH]\
  34. \n              [SETENV ON|OFF]\n";
  35.  
  36.     /* Where to find the different arguments. */
  37.  
  38. #define ARG_QUIT    1
  39. #define ARG_INFO    2
  40. #define ARG_BEEP    3
  41. #define ARG_CLICK    4
  42. #define ARG_CLICKVOLUME    5
  43. #define ARG_PRIORITY    6
  44. #define ARG_TEXTCOLOUR    7
  45. #define ARG_BACKCOLOUR    8
  46. #define ARG_ALARM    9
  47. #define ARG_ALARMTIME    10
  48. #define ARG_QUIET    11
  49. #define ARG_REFRESH    12
  50. #define ARG_SETENV    13
  51.  
  52.     /* Pop-up requester support structure. */
  53.  
  54. struct PopSupport
  55. {
  56.     ULONG    ps_Flags;
  57.     LONG    ps_TimeOut;
  58. };
  59.  
  60.     /* Pop-up requester support flags. */
  61.  
  62. #define PS_CENTER    0x00000001    /* Center window on screen. */
  63. #define PS_TIMEOUT    0x00000002    /* Wait for timeout. */
  64. #define PS_DONTMOVE    0x00000004    /* Don't move the pointer. */
  65. #define PS_BEEP        0x00000008    /* Beep on startup. */
  66. #define PS_STAYACTIVE    0x00000010    /* Keep the window activated. */
  67.  
  68.     /* For Workbench startability we need access to the icon
  69.      * info.
  70.      */
  71.  
  72. struct Library *IconBase;
  73. BOOL FromWorkbench = FALSE;
  74.  
  75.     /* Another library... */
  76.  
  77. extern struct IntuitionBase *IntuitionBase;
  78.  
  79.     /* Main communication structure. */
  80.  
  81. struct DSeg *DSeg;
  82.  
  83.     /* Stub, don't need this. */
  84.  
  85. long Chk_Abort() { return(0); }
  86.  
  87.     /* MovePointer(mp_Screen,mp_X,mp_Y) :
  88.      *
  89.      *    Moves the mouse pointer to a given position
  90.      *    on a screen.
  91.      */
  92.  
  93. LONG
  94. MovePointer(mp_Screen,mp_X,mp_Y)
  95. register struct Screen *mp_Screen;
  96. register LONG mp_X,mp_Y;
  97. {
  98.     static struct InputEvent mp_StaticEvent =
  99.     {
  100.         NULL,
  101.         IECLASS_POINTERPOS,
  102.         0,
  103.         IECODE_NOBUTTON,
  104.         0,0,0,0
  105.     };
  106.  
  107.     struct MsgPort        *mp_InputPort;
  108.     struct IOStdReq        *mp_InputRequest;
  109.     struct InputEvent    *mp_FakeEvent;
  110.  
  111.     register LONG mp_Success = FALSE;
  112.  
  113.     if(mp_InputPort = (struct MsgPort *)CreatePort(NULL,0))
  114.     {
  115.         if(mp_InputRequest = (struct IOStdReq *)CreateStdIO(mp_InputPort))
  116.         {
  117.             if(!OpenDevice("input.device",0,mp_InputRequest,0))
  118.             {
  119.                 if(mp_FakeEvent = (struct InputEvent *)AllocMem(sizeof(struct InputEvent),MEMF_PUBLIC))
  120.                 {
  121.                     CopyMem(&mp_StaticEvent,mp_FakeEvent,sizeof(struct InputEvent));
  122.  
  123.                     mp_InputRequest -> io_Command    = IND_WRITEEVENT;
  124.                     mp_InputRequest -> io_Flags    = 0;
  125.                     mp_InputRequest -> io_Length    = sizeof(struct InputEvent);
  126.                     mp_InputRequest -> io_Data    = (APTR)mp_FakeEvent;
  127.  
  128.                     mp_FakeEvent -> ie_X = mp_X;
  129.                     mp_FakeEvent -> ie_Y = mp_Y;
  130.  
  131.                     if(!(mp_Screen -> ViewPort . Modes & HIRES))
  132.                         mp_FakeEvent -> ie_X *= 2;
  133.  
  134.                     if(!(mp_Screen -> ViewPort . Modes & LACE))
  135.                         mp_FakeEvent -> ie_Y *= 2;
  136.  
  137.                     mp_FakeEvent -> ie_Y += (2 * mp_Screen -> TopEdge);
  138.  
  139.                     DoIO(mp_InputRequest);
  140.  
  141.                     mp_Success = TRUE;
  142.  
  143.                     FreeMem(mp_FakeEvent,sizeof(struct InputEvent));
  144.                 }
  145.  
  146.                 CloseDevice(mp_InputRequest);
  147.             }
  148.  
  149.             DeleteStdIO(mp_InputRequest);
  150.         }
  151.  
  152.         DeletePort(mp_InputPort);
  153.     }
  154.  
  155.     return(mp_Success);
  156. }
  157.  
  158.     /* WriteConsole(wc_Window,wc_String) :
  159.      *
  160.      *    Writes a string to a window (via the console.device).
  161.      */
  162.  
  163. LONG
  164. WriteConsole(wc_Window,wc_String)
  165. register struct Window *wc_Window;
  166. register UBYTE *wc_String;
  167. {
  168.     register struct IOStdReq    *wc_ConWrite;
  169.     register struct MsgPort        *wc_ConPort;
  170.  
  171.     register LONG wc_Success = FALSE;
  172.  
  173.     if(wc_ConPort = (struct MsgPort *)CreatePort(NULL,0))
  174.     {
  175.         if(wc_ConWrite = (struct IOStdReq *)CreateStdIO(wc_ConPort))
  176.         {
  177.             wc_ConWrite -> io_Data    = (APTR)wc_Window;
  178.             wc_ConWrite -> io_Length= sizeof(struct Window);
  179.  
  180.             if(!OpenDevice("console.device",0,wc_ConWrite,0))
  181.             {
  182.                 wc_ConWrite -> io_Command    = CMD_WRITE;
  183.                 wc_ConWrite -> io_Data        = (APTR)"\x9B0 p";
  184.                 wc_ConWrite -> io_Length    = -1;
  185.  
  186.                 DoIO(wc_ConWrite);
  187.  
  188.                 wc_ConWrite -> io_Data        = (APTR)wc_String;
  189.                 wc_ConWrite -> io_Length    = -1;
  190.  
  191.                 DoIO(wc_ConWrite);
  192.  
  193.                 wc_Success = TRUE;
  194.  
  195.                 CloseDevice(wc_ConWrite);
  196.             }
  197.  
  198.             DeleteStdIO(wc_ConWrite);
  199.         }
  200.  
  201.         DeletePort(wc_ConPort);
  202.     }
  203.  
  204.     return(wc_Success);
  205. }
  206.  
  207.     /* CalcDimensions(cd_String,cd_Width,cd_Height,cd_MaxWidth) :
  208.      *
  209.      *    Calculates the width and height of a formatted
  210.      *    string block.
  211.      */
  212.  
  213. void
  214. CalcDimensions(cd_String,cd_Width,cd_Height,cd_MaxWidth)
  215. UBYTE *cd_String;
  216. LONG *cd_Width,*cd_Height,cd_MaxWidth;
  217. {
  218.     LONG i,cd_InLine = 0,cd_NumLines = 0;
  219.  
  220.     *cd_Width = *cd_Height = 0;
  221.  
  222.     for(i = 0 ; i < strlen(cd_String) ; i++)
  223.     {
  224.         if(cd_String[i] == '\n' || cd_InLine == cd_MaxWidth)
  225.         {
  226.             if(cd_InLine > *cd_Width)
  227.                 *cd_Width = cd_InLine;
  228.  
  229.             cd_NumLines++;
  230.             cd_InLine = 0;
  231.  
  232.             continue;
  233.         }
  234.  
  235.         if(cd_String[i] == '\33')
  236.         {
  237.             while(cd_String[i] != 'm' && cd_String[i] != 'w' && i < strlen(cd_String))
  238.                 i++;
  239.  
  240.             if(i >= strlen(cd_String))
  241.                 i = strlen(cd_String) - 1;
  242.  
  243.             continue;
  244.         }
  245.  
  246.         if(cd_String[i] < ' ')
  247.             continue;
  248.  
  249.         cd_InLine++;
  250.     }
  251.  
  252.     *cd_Height = cd_NumLines;
  253.  
  254.     if(cd_InLine > *cd_Width)
  255.         *cd_Width = cd_InLine;
  256. }
  257.  
  258.     /* ClearGadgetGround(cgg_RPort,cgg_Gadget) :
  259.      *
  260.      *    Clears the background of a gadget.
  261.      */
  262.  
  263. void
  264. ClearGadgetGround(cgg_RPort,cgg_Gadget)
  265. struct RastPort *cgg_RPort;
  266. struct Gadget *cgg_Gadget;
  267. {
  268.     SetAPen(cgg_RPort,2);
  269.  
  270.     SetDrMd(cgg_RPort,JAM1);
  271.  
  272.     RectFill(cgg_RPort,cgg_Gadget -> LeftEdge,cgg_Gadget -> TopEdge,cgg_Gadget -> LeftEdge + cgg_Gadget -> Width - 1,cgg_Gadget -> TopEdge + cgg_Gadget -> Height - 1);
  273.  
  274.     SetAPen(cgg_RPort,1);
  275. }
  276.  
  277.     /* PopRequest(pr_ParentWindow,pr_TitleText,pr_BodyText,pr_PosText,pr_NegText,pr_Default,pr_ExtraInfo) :
  278.      *
  279.      *    Creates a pop-up requester, note: this function is reentrant,
  280.      *    just like all functions above.
  281.      */
  282.  
  283. LONG
  284. PopRequest(pr_ParentWindow,pr_TitleText,pr_BodyText,pr_PosText,pr_NegText,pr_Default,pr_ExtraInfo)
  285. struct Window *pr_ParentWindow;
  286. UBYTE *pr_TitleText,*pr_BodyText,*pr_PosText,*pr_NegText;
  287. LONG pr_Default;
  288. struct PopSupport *pr_ExtraInfo;
  289. {
  290.     static struct NewWindow pr_StaticNewWindow =
  291.     {
  292.         0,0,
  293.         0,1,
  294.         0,1,
  295.         VANILLAKEY | MOUSEBUTTONS | GADGETUP | CLOSEWINDOW,
  296.         RMBTRAP | WINDOWDRAG | WINDOWDEPTH,
  297.         (struct Gadget *)NULL,
  298.         (struct Image *)NULL,
  299.         (STRPTR)NULL,
  300.         (struct Screen *)NULL,
  301.         (struct BitMap *)NULL,
  302.         0,0,
  303.         0,0,
  304.         WBENCHSCREEN
  305.     };
  306.  
  307.     static struct Gadget pr_StaticGadget =
  308.     {
  309.         (struct Gadget *)NULL,
  310.         0,0,
  311.         0,0,
  312.         GADGHBOX,
  313.         RELVERIFY | GADGIMMEDIATE,
  314.         BOOLGADGET,
  315.         (APTR)NULL,
  316.         (APTR)NULL,
  317.         (struct IntuiText *)NULL,
  318.         NULL,
  319.         (APTR)NULL,
  320.         0,
  321.         (APTR)NULL
  322.     };
  323.  
  324.     static struct TextAttr pr_TextAttr =
  325.     {
  326.         (UBYTE *)"topaz.font",
  327.         8,
  328.         FS_NORMAL,
  329.         FPF_ROMFONT
  330.     };
  331.  
  332.     struct NewWindow    *pr_NewWindow;
  333.     struct Window        *pr_Window;
  334.     struct IntuiMessage    *pr_IMsg;
  335.     struct Gadget        *pr_PosGadget = NULL,*pr_NegGadget = NULL,*pr_TempGadget;
  336.  
  337.     struct Screen         pr_Screen;
  338.     struct TextFont        *pr_TextFont;
  339.  
  340.     APTR             pr_LastScreen,pr_LastWindow;
  341.  
  342.     LONG             pr_Width,pr_Height;
  343.     LONG             pr_Result = FALSE;
  344.  
  345.     LONG             pr_TickCount = 0;
  346.  
  347.     if(!pr_BodyText)
  348.         return(pr_Result);
  349.  
  350.     if(!(pr_NewWindow = (struct NewWindow *)AllocMem(sizeof(struct NewWindow),MEMF_PUBLIC)))
  351.         return(pr_Result);
  352.  
  353.     CopyMem(&pr_StaticNewWindow,pr_NewWindow,sizeof(struct NewWindow));
  354.  
  355.     if(pr_ParentWindow)
  356.     {
  357.         pr_NewWindow -> Type    = CUSTOMSCREEN;
  358.         pr_NewWindow -> Screen    = pr_ParentWindow -> WScreen;
  359.     }
  360.     else
  361.         OpenWorkBench();
  362.  
  363.     if(!GetScreenData(&pr_Screen,sizeof(struct Screen),pr_NewWindow -> Type,pr_NewWindow -> Screen))
  364.     {
  365.         FreeMem(pr_NewWindow,sizeof(struct NewWindow));
  366.         return(pr_Result);
  367.     }
  368.  
  369.     CalcDimensions(pr_BodyText,&pr_Width,&pr_Height,(pr_Screen . Width - 6) / 8);
  370.  
  371.     if(pr_Height > (pr_Screen . Height - 15 - 13) / 8)
  372.     {
  373.         FreeMem(pr_NewWindow,sizeof(struct NewWindow));
  374.         return(pr_Result);
  375.     }
  376.  
  377.     pr_NewWindow -> Width    = pr_Width * 8 + 6 + 4;
  378.     pr_NewWindow -> Height    = pr_Height * 8 + 15 + 19 + 2;
  379.  
  380.     if(pr_TitleText)
  381.         pr_NewWindow -> Title = pr_TitleText;
  382.     else
  383.         pr_NewWindow -> Title = (UBYTE *)"System Request";
  384.  
  385.     if(!pr_PosText && !pr_NegText)
  386.         pr_NegText = (UBYTE *)"Okay";
  387.  
  388.     if(pr_PosText)
  389.     {
  390.         if(!(pr_PosGadget = (struct Gadget *)AllocMem(sizeof(struct Gadget),MEMF_PUBLIC)))
  391.         {
  392.             FreeMem(pr_NewWindow,sizeof(struct NewWindow));
  393.             return(pr_Result);
  394.         }
  395.  
  396.         CopyMem(&pr_StaticGadget,pr_PosGadget,sizeof(struct Gadget));
  397.  
  398.         pr_PosGadget -> Width    = 8 * strlen(pr_PosText) + 4;
  399.         pr_PosGadget -> Height    = 8 + 2;
  400.  
  401.         pr_PosGadget -> LeftEdge= 3 + 2 + 3;
  402.         pr_PosGadget -> TopEdge    = pr_NewWindow -> Height - 13 - 1;
  403.     }
  404.  
  405.     if(pr_NegText)
  406.     {
  407.         if(!(pr_NegGadget = (struct Gadget *)AllocMem(sizeof(struct Gadget),MEMF_PUBLIC)))
  408.         {
  409.             FreeMem(pr_NewWindow,sizeof(struct NewWindow));
  410.  
  411.             if(pr_PosGadget)
  412.                 FreeMem(pr_PosGadget,sizeof(struct Gadget));
  413.  
  414.             return(pr_Result);
  415.         }
  416.  
  417.         CopyMem(&pr_StaticGadget,pr_NegGadget,sizeof(struct Gadget));
  418.  
  419.         pr_NegGadget -> Width    = 8 * strlen(pr_NegText) + 4;
  420.         pr_NegGadget -> Height    = 8 + 2;
  421.  
  422.         pr_Width = pr_NegGadget -> Width + 6 + 4 + 6;
  423.  
  424.         if(pr_PosGadget)
  425.             pr_Width += (pr_PosGadget -> Width + 12);
  426.  
  427.         if(pr_NewWindow -> Width < pr_Width)
  428.             pr_NewWindow -> Width = pr_Width;
  429.  
  430.         pr_NegGadget -> LeftEdge= pr_NewWindow -> Width - pr_NegGadget -> Width - 3 - 2 - 3;
  431.         pr_NegGadget -> TopEdge    = pr_NewWindow -> Height - 13 - 1;
  432.  
  433.         pr_NegGadget -> GadgetID= 1;
  434.     }
  435.  
  436.     if(!pr_NegGadget && pr_NewWindow -> Width < pr_PosGadget -> Width + 6 + 4 + 6)
  437.         pr_NewWindow -> Width = pr_PosGadget -> Width + 6 + 4 + 6;
  438.  
  439.     if(pr_Default && !pr_PosGadget)
  440.         pr_Default = FALSE;
  441.  
  442.     if(!pr_Default && !pr_NegGadget)
  443.         pr_Default = TRUE;
  444.  
  445.     if(pr_Default)
  446.         pr_TempGadget = pr_PosGadget;
  447.     else
  448.         pr_TempGadget = pr_NegGadget;
  449.  
  450.     pr_NewWindow -> LeftEdge= pr_Screen . MouseX - (pr_TempGadget -> LeftEdge + pr_TempGadget -> Width / 2);
  451.     pr_NewWindow -> TopEdge    = pr_Screen . MouseY - (pr_TempGadget -> TopEdge + pr_TempGadget -> Height / 2);
  452.  
  453.     while(pr_NewWindow -> LeftEdge < 0)
  454.         pr_NewWindow -> LeftEdge++;
  455.  
  456.     while(pr_NewWindow -> TopEdge < 0)
  457.         pr_NewWindow -> TopEdge++;
  458.  
  459.     while(pr_NewWindow -> LeftEdge + pr_NewWindow -> Width >= pr_Screen . Width)
  460.         pr_NewWindow -> LeftEdge--;
  461.  
  462.     while(pr_NewWindow -> TopEdge + pr_NewWindow -> Height >= pr_Screen . Height)
  463.         pr_NewWindow -> TopEdge--;
  464.  
  465.     if(!(pr_TextFont = (struct TextFont *)OpenFont(&pr_TextAttr)))
  466.     {
  467.         if(pr_PosGadget)
  468.             FreeMem(pr_PosGadget,sizeof(struct Gadget));
  469.  
  470.         if(pr_NegGadget)
  471.             FreeMem(pr_NegGadget,sizeof(struct Gadget));
  472.  
  473.         FreeMem(pr_NewWindow,sizeof(struct NewWindow));
  474.  
  475.         return(pr_Result);
  476.     }
  477.  
  478.     if(pr_ExtraInfo)
  479.     {
  480.         if(pr_ExtraInfo -> ps_Flags & PS_CENTER)
  481.         {
  482.             pr_NewWindow -> LeftEdge    = (pr_Screen . Width - pr_NewWindow -> Width) / 2;
  483.             pr_NewWindow -> TopEdge        = (pr_Screen . Height - pr_NewWindow -> Height) / 2;
  484.         }
  485.  
  486.         if(pr_ExtraInfo -> ps_Flags & PS_TIMEOUT)
  487.             pr_NewWindow -> IDCMPFlags |= INTUITICKS;
  488.  
  489.         if(pr_ExtraInfo -> ps_Flags & PS_STAYACTIVE)
  490.             pr_NewWindow -> IDCMPFlags |= INACTIVEWINDOW;
  491.     }
  492.  
  493.     if(!(pr_Window = (struct Window *)OpenWindow(pr_NewWindow)))
  494.     {
  495.         CloseFont(pr_TextFont);
  496.  
  497.         if(pr_PosGadget)
  498.             FreeMem(pr_PosGadget,sizeof(struct Gadget));
  499.  
  500.         if(pr_NegGadget)
  501.             FreeMem(pr_NegGadget,sizeof(struct Gadget));
  502.  
  503.         FreeMem(pr_NewWindow,sizeof(struct NewWindow));
  504.  
  505.         return(pr_Result);
  506.     }
  507.  
  508.     SetFont(pr_Window -> RPort,pr_TextFont);
  509.  
  510.     WriteConsole(pr_Window,pr_BodyText);
  511.  
  512.     if(pr_PosGadget)
  513.     {
  514.         AddGadget(pr_Window,pr_PosGadget,1);
  515.  
  516.         ClearGadgetGround(pr_Window -> RPort,pr_PosGadget);
  517.  
  518.         Move(pr_Window -> RPort,pr_PosGadget -> LeftEdge + 2,pr_PosGadget -> TopEdge + 1 + pr_TextFont -> tf_Baseline);
  519.         Text(pr_Window -> RPort,pr_PosText,strlen(pr_PosText));
  520.     }
  521.  
  522.     if(pr_NegGadget)
  523.     {
  524.         AddGadget(pr_Window,pr_NegGadget,1);
  525.  
  526.         ClearGadgetGround(pr_Window -> RPort,pr_NegGadget);
  527.  
  528.         Move(pr_Window -> RPort,pr_NegGadget -> LeftEdge + 2,pr_NegGadget -> TopEdge + 1 + pr_TextFont -> tf_Baseline);
  529.         Text(pr_Window -> RPort,pr_NegText,strlen(pr_NegText));
  530.     }
  531.  
  532.     Forbid();
  533.     {
  534.         ULONG IntuiLock;
  535.  
  536.         IntuiLock = LockIBase(NULL);
  537.  
  538.         pr_LastScreen    = (APTR)IntuitionBase -> FirstScreen;
  539.         pr_LastWindow    = (APTR)IntuitionBase -> ActiveWindow;
  540.  
  541.         UnlockIBase(IntuiLock);
  542.     }
  543.     Permit();
  544.  
  545.     MoveScreen(pr_Window -> WScreen,0,- pr_Window -> WScreen -> TopEdge);
  546.     ScreenToFront(pr_Window -> WScreen);
  547.     ActivateWindow(pr_Window);
  548.  
  549.     if(pr_ExtraInfo && pr_ExtraInfo -> ps_Flags & PS_DONTMOVE)
  550.         goto Skip1;
  551.  
  552.     MovePointer(pr_Window -> WScreen,
  553.         pr_Window -> LeftEdge + (pr_TempGadget -> LeftEdge + pr_TempGadget -> Width / 2),
  554.         pr_Window -> TopEdge + (pr_TempGadget -> TopEdge + pr_TempGadget -> Height / 2));
  555.  
  556. Skip1:    if(pr_ExtraInfo)
  557.     {
  558.         if(pr_ExtraInfo -> ps_Flags & PS_BEEP)
  559.             DisplayBeep(pr_Window -> WScreen);
  560.  
  561.         if(pr_ExtraInfo -> ps_Flags & PS_TIMEOUT)
  562.             pr_TickCount = pr_ExtraInfo -> ps_TimeOut * 10;
  563.     }
  564.  
  565.     FOREVER
  566.     {
  567.         ULONG pr_Class,pr_Code,pr_Qualifier;
  568.         struct Gadget *pr_Gadget;
  569.  
  570.         WaitPort(pr_Window -> UserPort);
  571.  
  572.         if(pr_IMsg = (struct IntuiMessage *)GetMsg(pr_Window -> UserPort))
  573.         {
  574.             pr_Class    = pr_IMsg -> Class;
  575.             pr_Code        = pr_IMsg -> Code;
  576.             pr_Qualifier    = pr_IMsg -> Qualifier;
  577.             pr_Gadget    = (struct Gadget *)pr_IMsg -> IAddress;
  578.  
  579.             ReplyMsg(pr_IMsg);
  580.  
  581.             if(pr_Class == INTUITICKS)
  582.             {
  583.                 if(pr_TickCount)
  584.                     pr_TickCount--;
  585.                 else
  586.                 {
  587.                     pr_Result = pr_Default;
  588.                     break;
  589.                 }
  590.  
  591.                 continue;
  592.             }
  593.  
  594.             if(pr_Class == INACTIVEWINDOW)
  595.             {
  596.                 MoveScreen(pr_Window -> WScreen,0,- pr_Window -> WScreen -> TopEdge);
  597.                 ScreenToFront(pr_Window -> WScreen);
  598.                 ActivateWindow(pr_Window);
  599.  
  600.                 if(!(pr_ExtraInfo -> ps_Flags & PS_DONTMOVE))
  601.                 {
  602.                     MovePointer(pr_Window -> WScreen,
  603.                         pr_Window -> LeftEdge + (pr_TempGadget -> LeftEdge + pr_TempGadget -> Width / 2),
  604.                         pr_Window -> TopEdge + (pr_TempGadget -> TopEdge + pr_TempGadget -> Height / 2));
  605.                 }
  606.  
  607.                 if(pr_ExtraInfo -> ps_Flags & PS_BEEP)
  608.                     DisplayBeep(pr_Window -> WScreen);
  609.  
  610.                 continue;
  611.             }
  612.  
  613.             if(pr_Class == GADGETUP)
  614.             {
  615.                 if(pr_Gadget -> GadgetID == 0)
  616.                     pr_Result = TRUE;
  617.  
  618.                 break;
  619.             }
  620.  
  621.             if(pr_Class == CLOSEWINDOW)
  622.                 break;
  623.  
  624.             if(pr_Class == VANILLAKEY)
  625.             {
  626.                 pr_Code = toupper(pr_Code);
  627.  
  628.                 if((pr_Code == 'Y' || pr_Code == 'J' || pr_Code == 'V' || pr_Code == 'C' || pr_Code == 'R' || pr_Code == '\n') && pr_PosText)
  629.                 {
  630.                     pr_Result = TRUE;
  631.                     break;
  632.                 }
  633.  
  634.                 if((pr_Code == 'N' || pr_Code == 'Q' || pr_Code == 'B' || pr_Code == '\33') && pr_NegText)
  635.                     break;
  636.  
  637.                 continue;
  638.             }
  639.  
  640.             if(pr_Class == MOUSEBUTTONS && pr_Code == MENUDOWN)
  641.             {
  642.                 MovePointer(pr_Window -> WScreen,
  643.                     pr_Window -> LeftEdge+ (pr_TempGadget -> LeftEdge + pr_TempGadget -> Width / 2),
  644.                     pr_Window -> TopEdge + (pr_TempGadget -> TopEdge  + pr_TempGadget -> Height / 2));
  645.             }
  646.         }
  647.     }
  648.  
  649.     CloseFont(pr_TextFont);
  650.  
  651.     if(pr_PosGadget)
  652.     {
  653.         RemoveGadget(pr_Window,pr_PosGadget);
  654.         FreeMem(pr_PosGadget,sizeof(struct Gadget));
  655.     }
  656.  
  657.     if(pr_NegGadget)
  658.     {
  659.         RemoveGadget(pr_Window,pr_NegGadget);
  660.         FreeMem(pr_NegGadget,sizeof(struct Gadget));
  661.     }
  662.  
  663.     FreeMem(pr_NewWindow,sizeof(struct NewWindow));
  664.  
  665.     CloseWindow(pr_Window);
  666.  
  667.     ScreenToFront(pr_LastScreen);
  668.     ActivateWindow(pr_LastWindow);
  669.  
  670.     return(pr_Result);
  671. }
  672.  
  673.     /* ProcessIcon():
  674.      *
  675.      *    To add startability from Workbench this function
  676.      *    checks for the approritate tooltype entries.
  677.      */
  678.  
  679. void
  680. ProcessIcon()
  681. {
  682.     register struct DiskObject *DiskObject,*GetDiskObject();
  683.     extern struct WBStartup *WBenchMsg;
  684.     char *Option,*FindToolType();
  685.  
  686.         /* No need to continue? */
  687.  
  688.     if(!DSeg || !FromWorkbench)
  689.     {
  690.         if(!DSeg && FromWorkbench)
  691.             PopRequest(NULL,"DClock problem:","Can't find \33[1m\"DClock-Handler\"\33[0m!\nCheck L: and current directory.",NULL,"Continue?",FALSE,NULL);
  692.  
  693.         return;
  694.     }
  695.  
  696.         /* Try to open the icon.library. */
  697.  
  698.     if(!(IconBase = (struct Library *)OpenLibrary("icon.library",0)))
  699.     {
  700.         PopRequest(NULL,"DClock problem:","Unable to open \33[1micon.library\33[0m!",NULL,"Continue?",FALSE,NULL);
  701.         return;
  702.     }
  703.  
  704.         /* Can we read the icon file please? */
  705.  
  706.     if(!(DiskObject = (struct DiskObject *)GetDiskObject(WBenchMsg -> sm_ArgList -> wa_Name)))
  707.     {
  708.         PopRequest(NULL,"DClock problem:","Couldn't read icon information file!",NULL,"Continue?",FALSE,NULL);
  709.  
  710.         CloseLibrary(IconBase);
  711.         return;
  712.     }
  713.  
  714.         /* Adjust Click volume? */
  715.  
  716.     if(Option = FindToolType(DiskObject -> do_ToolTypes,"CLICKVOLUME"))
  717.     {
  718.         if(Atol(Option) > 64 || Atol(Option) < 0)
  719.             PopRequest(NULL,"DClock problem:","Illegal value for click volume (must be between 0 and 64)!",NULL,"Continue?",FALSE,NULL);
  720.         else
  721.             DSeg -> ClickVolume = Atol(Option);
  722.     }
  723.  
  724.         /* Adjust task priority? */
  725.  
  726.     if((Option = FindToolType(DiskObject -> do_ToolTypes,"PRIORITY")) && DSeg -> Child)
  727.     {
  728.         if(Atol(Option) > 127 || Atol(Option) < -127)
  729.             PopRequest(NULL,"DClock problem:","Illegal value for handler task priority (must be between -127 and 127)!",NULL,"Continue?",FALSE,NULL);
  730.         else
  731.         {
  732.             DSeg -> Priority = Atol(Option);
  733.             SetTaskPri(DSeg -> Child,DSeg -> Priority);
  734.         }
  735.     }
  736.  
  737.         /* Turn DisplayBeep() off? */
  738.  
  739.     if(Option = FindToolType(DiskObject -> do_ToolTypes,"BEEP"))
  740.     {
  741.         if(!Strcmp(Option,"OFF"))
  742.             DSeg -> Beep = FALSE;
  743.         else
  744.         {
  745.             if(!Strcmp(Option,"ON"))
  746.                 DSeg -> Beep = TRUE;
  747.             else
  748.                 PopRequest(NULL,"DClock problem:","Beep settings not understood (must be OFF or ON)!",NULL,"Continue?",FALSE,NULL);
  749.         }
  750.     }
  751.  
  752.         /* Turn keyboard click off? */
  753.  
  754.     if(Option = FindToolType(DiskObject -> do_ToolTypes,"CLICK"))
  755.     {
  756.         if(!Strcmp(Option,"OFF"))
  757.             DSeg -> Click = FALSE;
  758.         else
  759.         {
  760.             if(!Strcmp(Option,"ON"))
  761.                 DSeg -> Click = TRUE;
  762.             else
  763.                 PopRequest(NULL,"DClock problem:","Click settings not understood (must be OFF or ON)!",NULL,"Continue?",FALSE,NULL);
  764.         }
  765.     }
  766.  
  767.         /* Set text colour? */
  768.  
  769.     if(Option = FindToolType(DiskObject -> do_ToolTypes,"TEXTCOLOUR"))
  770.         DSeg -> TextColour = Atol(Option);
  771.  
  772.         /* Set background colour? */
  773.  
  774.     if(Option = FindToolType(DiskObject -> do_ToolTypes,"BACKCOLOUR"))
  775.         DSeg -> BackColour = Atol(Option);
  776.  
  777.         /* Turn alarm on? */
  778.  
  779.     if(Option = FindToolType(DiskObject -> do_ToolTypes,"ALARM"))
  780.     {
  781.         if(!Strcmp(Option,"OFF"))
  782.             DSeg -> Alarm = FALSE;
  783.         else
  784.         {
  785.             if(!Strcmp(Option,"ON"))
  786.                 DSeg -> Alarm = TRUE;
  787.             else
  788.                 PopRequest(NULL,"DClock problem:","Alarm settings not understood (must be OFF or ON)!",NULL,"Continue?",FALSE,NULL);
  789.         }
  790.     }
  791.  
  792.         /* Set alarm time? */
  793.  
  794.     if(Option = FindToolType(DiskObject -> do_ToolTypes,"ALARMTIME"))
  795.     {
  796.         char TimeBuff[3];
  797.         register long TheTime;
  798.  
  799.         TimeBuff[2] = 0;
  800.  
  801.         TimeBuff[0] = Option[0];
  802.         TimeBuff[1] = Option[1];
  803.  
  804.         TheTime = Atol(TimeBuff);
  805.  
  806.         if(TheTime >= 0 && TheTime <= 23)
  807.             DSeg -> AlarmHour = TheTime;
  808.         else
  809.             PopRequest(NULL,"DClock problem:","Illegal value for alarm hour (must be between 0 and 23)!",NULL,"Continue?",FALSE,NULL);
  810.  
  811.         TimeBuff[0] = Option[3];
  812.         TimeBuff[1] = Option[4];
  813.  
  814.         TheTime = Atol(TimeBuff);
  815.  
  816.         if(TheTime >= 0 && TheTime <= 59)
  817.             DSeg -> AlarmMinute = TheTime;
  818.         else
  819.             PopRequest(NULL,"DClock problem:","Illegal value for alarm minute (must be between 0 and 59)!",NULL,"Continue?",FALSE,NULL);
  820.  
  821.         TimeBuff[0] = Option[6];
  822.         TimeBuff[1] = Option[7];
  823.  
  824.         TheTime = Atol(TimeBuff);
  825.  
  826.         if(TheTime >= 0 && TheTime <= 59)
  827.             DSeg -> AlarmSecond = TheTime;
  828.         else
  829.             PopRequest(NULL,"DClock problem:","Illegal value for alarm seconds (must be between 0 and 59)!",NULL,"Continue?",FALSE,NULL);
  830.     }
  831.  
  832.         /* Set environment variables? */
  833.  
  834.     if(Option = FindToolType(DiskObject -> do_ToolTypes,"SETENV"))
  835.     {
  836.         if(!Strcmp(Option,"OFF"))
  837.             DSeg -> SetEnv = FALSE;
  838.         else
  839.         {
  840.             if(!Strcmp(Option,"ON"))
  841.                 DSeg -> SetEnv = TRUE;
  842.             else
  843.                 PopRequest(NULL,"DClock problem:","Environment settings not understood (must be OFF or ON)!",NULL,"Continue?",FALSE,NULL);
  844.         }
  845.     }
  846.  
  847.         /* Free the rest... */
  848.  
  849.     FreeDiskObject(DiskObject);
  850.  
  851.     CloseLibrary(IconBase);
  852. }
  853.  
  854.     /* main(argc,argv):
  855.      *
  856.      *    That's where all the trouble starts.
  857.      */
  858.  
  859. void
  860. main(argc,argv)
  861. long argc;
  862. char *argv[];
  863. {
  864.     register BOOL Quiet = FALSE;
  865.     register struct Process *ThatsMe = (struct Process *)FindTask(NULL);
  866.  
  867.         /* Init important pointers. */
  868.  
  869.     if(!ThatsMe -> pr_CLI)
  870.         FromWorkbench = TRUE;
  871.  
  872.         /* Are we already running? */
  873.  
  874.     DSeg = (struct DSeg *)FindPort(PORTNAME);
  875.  
  876.         /* Restart? */
  877.  
  878.     if(FromWorkbench && DSeg)
  879.     {
  880.         ProcessIcon();
  881.         exit(0);
  882.     }
  883.  
  884.         /* Yeah... push it! */
  885.  
  886.     if(FromWorkbench)
  887.         goto PushIt;
  888.  
  889.         /* Be quiet? */
  890.  
  891.     if(argv[ARG_QUIET])
  892.         Quiet = TRUE;
  893.  
  894.         /* No argument and DClock's already running? */
  895.  
  896.     if(argc < 2 && DSeg)
  897.     {
  898.         Printf("Can't install \33[1mDClock\33[0m, handler process \33[33malready running\33[31m\7!\n");
  899.  
  900.         exit(0);
  901.     }
  902.  
  903.         /* User wants information. */
  904.  
  905.     if(argv[ARG_INFO])
  906.     {
  907.         Printf("\n\33[1m\33[33mDClock\33[0m\33[31m - A \33[33mD\33[31mumb \33[33mClock\33[31m. Renders time and date\n");
  908.         Printf("         into the Workbench title bar. Place\n");
  909.         Printf("         \33[33mDClock-Handler\33[31m in L:, \33[33mDClock\33[31m somewhere\n");
  910.         Printf("         in C: or in SYS:. Type '\33[1m\33[33mDClock\33[31m\33[0m' to\n");
  911.         Printf("         install, '\33[1m\33[33mDClock quit\33[31m\33[0m' to remove.\n\n");
  912.         Printf("         \33[33mDClock\33[31m is \33[1mfree\33[0m and in the \33[33m\33[1mPUBLIC-DOMAIN\33[31m\33[0m!\n\n");
  913.  
  914.         Printf("\33[1m\33[33mAuthor\33[31m\33[0m - Olaf Barthel of MXM\n");
  915.         Printf("         Brabeckstrasse 35\n");
  916.         Printf("         D-3000 Hannover 71\n\n");
  917.  
  918.         Printf("     Federal Republic of Germany.\n\n");
  919.  
  920.         exit(0);
  921.     }
  922.  
  923.         /* Terminate dumb clock? */
  924.  
  925.     if(argv[ARG_QUIT])
  926.     {
  927.         Printf("Removing \33[1m\33[33mDClock\33[31m\33[0m, ");
  928.  
  929.             /* Segment not loaded. */
  930.  
  931.         if(!DSeg)
  932.         {
  933.             Printf("failed!\7\n");
  934.             exit(0);
  935.         }
  936.  
  937.             /* We are the caller. */
  938.  
  939.         DSeg -> Father = (struct Task *)ThatsMe;
  940.  
  941.             /* Child still present? */
  942.  
  943.         if(DSeg -> Child)
  944.         {
  945.             Signal(DSeg -> Child,SIGBREAKF_CTRL_D);
  946.             Wait(SIGBREAKF_CTRL_D);
  947.         }
  948.  
  949.             /* Remove port and associated data. */
  950.  
  951.         RemPort(&DSeg -> Port);
  952.         FreeMem(DSeg -> Port . mp_Node . ln_Name,sizeof(PORTNAME));
  953.  
  954.         if(DSeg -> Segment)
  955.             UnLoadSeg(DSeg -> Segment);
  956.  
  957.         FreeMem(DSeg,DSeg -> SegSize);
  958.  
  959.         Printf("OK.\n");
  960.  
  961.         exit(0);
  962.     }
  963.  
  964.         /* Create global communication structure. */
  965.  
  966. PushIt:    if(!DSeg)
  967.     {
  968.         if(DSeg = (struct DSeg *)AllocMem(sizeof(struct DSeg),MEMF_PUBLIC | MEMF_CLEAR))
  969.         {
  970.             ULONG Micros;
  971.  
  972.                 /* Dummy MessagePort. */
  973.  
  974.             DSeg -> Port . mp_Flags        = PA_IGNORE;
  975.             DSeg -> Port . mp_Node . ln_Pri    = 0;
  976.             DSeg -> Port . mp_Node . ln_Type= NT_MSGPORT;
  977.             DSeg -> Port . mp_Node . ln_Name= AllocMem(sizeof(PORTNAME),MEMF_PUBLIC);
  978.             DSeg -> Child            = NULL;
  979.             DSeg -> Father            = (struct Task *)ThatsMe;
  980.  
  981.                 /* For future expansion of this structure,
  982.                  * this will insure that any version of
  983.                  * DClock will be able to free the memory
  984.                  * occupied by the segment.
  985.                  */
  986.  
  987.             DSeg -> SegSize            = sizeof(struct DSeg);
  988.  
  989.                 /* We'll wait for this signal to come from
  990.                  * the handler process.
  991.                  */
  992.  
  993.             DSeg -> RingBack        = SIGBREAKF_CTRL_C;
  994.  
  995.                 /* Activate beep and click feature. */
  996.  
  997.             DSeg -> Beep            = TRUE;
  998.             DSeg -> Click            = TRUE;
  999.  
  1000.                 /* So we have valid time counter. */
  1001.  
  1002.             CurrentTime(&DSeg -> LastSecs,&Micros);
  1003.  
  1004.                 /* Click volume and handler priority. */
  1005.  
  1006.             DSeg -> ClickVolume        = 64;
  1007.             DSeg -> Priority        = 5;
  1008.  
  1009.                 /* Rendering colours. */
  1010.  
  1011.             DSeg -> TextColour        = 0;
  1012.             DSeg -> BackColour        = 1;
  1013.  
  1014.                 /* Set alarm default. */
  1015.  
  1016.             DSeg -> Alarm            = FALSE;
  1017.  
  1018.             DSeg -> AlarmHour        = 12;
  1019.             DSeg -> AlarmMinute        = 0;
  1020.             DSeg -> AlarmSecond        = 0;
  1021.  
  1022.                 /* Set environment variables. */
  1023.  
  1024.             DSeg -> SetEnv            = TRUE;
  1025.  
  1026.                 /* Install the current revision number. */
  1027.  
  1028.             DSeg -> Revision        = REVISION;
  1029.  
  1030.                 /* Changed handler priority. */
  1031.  
  1032.             if(argv[ARG_PRIORITY] && !FromWorkbench)
  1033.                 Printf("\33[1mDClock:\33[0m Handler priority set to %ld.\n",DSeg -> Priority = Atol(argv[ARG_PRIORITY]));
  1034.  
  1035.                 /* Init port. */
  1036.  
  1037.             strcpy(DSeg -> Port . mp_Node . ln_Name,PORTNAME);
  1038.  
  1039.             NewList(&DSeg -> Port . mp_MsgList);
  1040.  
  1041.             if(!FromWorkbench)
  1042.                 Printf("Installing \33[33m\33[1mDClock\33[0m\33[31m, ");
  1043.  
  1044.                 /* Load the handler code. */
  1045.  
  1046.             DSeg -> Segment = LoadSeg("DClock-Handler");
  1047.  
  1048.             if(!DSeg -> Segment)
  1049.                 DSeg -> Segment = LoadSeg("L:DClock-Handler");
  1050.  
  1051.             if(!DSeg -> Segment)
  1052.             {
  1053.                 if(!FromWorkbench)
  1054.                     Printf("unable to find \33[33mL:DClock-Handler\33[31m\7!\n");
  1055.                 else
  1056.                     PopRequest(NULL,"DClock problem:","Can't find \33[1m\"DClock-Handler\"\33[0m!\nCheck L: and current directory.",NULL,"Continue?",FALSE,NULL);
  1057.  
  1058.                 FreeMem(DSeg -> Port . mp_Node . ln_Name,sizeof(PORTNAME));
  1059.                 FreeMem(DSeg,DSeg -> SegSize);
  1060.             }
  1061.             else
  1062.             {
  1063.                     /* Install the port and start the handler. */
  1064.  
  1065.                 AddPort(&DSeg -> Port);
  1066.  
  1067.                 CreateProc("DClock-Handler",DSeg -> Priority,DSeg -> Segment,4096);
  1068.  
  1069.                     /* Wait for child task to ring back... */
  1070.  
  1071.                 Wait(SIGBREAKF_CTRL_C);
  1072.  
  1073.                 if(!DSeg -> Child)
  1074.                 {
  1075.                     if(!FromWorkbench)
  1076.                         Printf("\33[33mFAILED!\33[31m (care to retry?)\n");
  1077.                     else
  1078.                         PopRequest(NULL,"DClock problem:","Handler process didn't reply startup-message.",NULL,"Continue?",FALSE,NULL);
  1079.  
  1080.                     RemPort(&DSeg -> Port);
  1081.                     FreeMem(DSeg -> Port . mp_Node . ln_Name,sizeof(PORTNAME));
  1082.  
  1083.                     if(DSeg -> Segment)
  1084.                         UnLoadSeg(DSeg -> Segment);
  1085.  
  1086.                     FreeMem(DSeg,DSeg -> SegSize);
  1087.  
  1088.                     if(FromWorkbench)
  1089.                         Delay(TICKS_PER_SECOND * 2);
  1090.  
  1091.                     exit(20);
  1092.                 }
  1093.                 else
  1094.                 {
  1095.                     if(!FromWorkbench)
  1096.                         Printf("Okay. \33[33mDClock v1.%ld\33[31m, \33[3mby MXM.\33[0m \33[1mPUBLIC DOMAIN\33[0m.\n",REVISION);
  1097.                     else
  1098.                         PopRequest(NULL,"DClock v1.12:","Handler process successfully installed!\n\n\33[33mDClock\33[31m (C) Copyright 1989,1990 \33[3mby MXM.\33[0m \33[1mPUBLIC DOMAIN\33[0m.",NULL,"Continue?",FALSE,NULL);
  1099.                 }
  1100.             }
  1101.         }
  1102.     }
  1103.  
  1104.         /* Deal with the icon... */
  1105.  
  1106.     if(FromWorkbench)
  1107.     {
  1108.         ProcessIcon();
  1109.         exit(0);
  1110.     }
  1111.  
  1112.         /* Change click volume. */
  1113.  
  1114.     if(argv[ARG_CLICKVOLUME] && DSeg)
  1115.     {
  1116.         if(Atol(argv[ARG_CLICKVOLUME]) > 0)
  1117.         {
  1118.             if(!Quiet)
  1119.                 Printf("\33[1mDClock:\33[0m Click volume set to %ld.\n",DSeg -> ClickVolume = Atol(argv[ARG_CLICKVOLUME]));
  1120.         }
  1121.         else
  1122.             Puts(CLI_Help);
  1123.     }
  1124.  
  1125.         /* Change handler priority? */
  1126.  
  1127.     if(argv[ARG_PRIORITY] && DSeg)
  1128.     {
  1129.         if(DSeg -> Child)
  1130.         {
  1131.             if(!Quiet)
  1132.                 Printf("\33[1mDClock:\33[0m Handler priority set to %ld.\n",DSeg -> Priority = Atol(argv[ARG_PRIORITY]));
  1133.  
  1134.             SetTaskPri(DSeg -> Child,DSeg -> Priority);
  1135.         }
  1136.         else
  1137.             Puts("\33[1mDClock:\33[0m Unable to find handler task.");
  1138.     }
  1139.  
  1140.         /* Turn beeping on/off? */
  1141.  
  1142.     if(argv[ARG_BEEP] && DSeg)
  1143.     {
  1144.         if(!Strcmp(argv[ARG_BEEP],"OFF"))
  1145.         {
  1146.             if(!Quiet)
  1147.                 Puts("\33[1mDClock:\33[0m Beep disabled.");
  1148.  
  1149.             DSeg -> Beep = FALSE;
  1150.         }
  1151.         else
  1152.         {
  1153.             if(!Strcmp(argv[ARG_BEEP],"ON"))
  1154.             {
  1155.                 if(!Quiet)
  1156.                     Puts("\33[1mDClock:\33[0m Beep enabled.");
  1157.  
  1158.                 DSeg -> Beep = TRUE;
  1159.             }
  1160.             else
  1161.                 Puts(CLI_Help);
  1162.         }
  1163.     }
  1164.  
  1165.         /* Turn clicking on/off? */
  1166.  
  1167.     if(argv[ARG_CLICK])
  1168.     {
  1169.         if(!Strcmp(argv[ARG_CLICK],"OFF"))
  1170.         {
  1171.             if(!Quiet)
  1172.                 Puts("\33[1mDClock:\33[0m Click disabled.");
  1173.  
  1174.             DSeg -> Click = FALSE;
  1175.         }
  1176.         else
  1177.         {
  1178.             if(!Strcmp(argv[ARG_CLICK],"ON"))
  1179.             {
  1180.                 if(!Quiet)
  1181.                     Puts("\33[1mDClock:\33[0m Click enabled.");
  1182.  
  1183.                 DSeg -> Click = TRUE;
  1184.             }
  1185.             else
  1186.                 Puts(CLI_Help);
  1187.         }
  1188.     }
  1189.  
  1190.         /* Select new front colour? */
  1191.  
  1192.     if(argv[ARG_TEXTCOLOUR])
  1193.     {
  1194.         DSeg -> TextColour = Atol(argv[ARG_TEXTCOLOUR]);
  1195.  
  1196.         if(!Quiet)
  1197.             Printf("\33[1mDClock:\33[0m Text colour set to %ld.\n",DSeg -> TextColour);
  1198.     }
  1199.  
  1200.         /* Select new background colour? */
  1201.  
  1202.     if(argv[ARG_BACKCOLOUR])
  1203.     {
  1204.         DSeg -> BackColour = Atol(argv[ARG_BACKCOLOUR]);
  1205.  
  1206.         if(!Quiet)
  1207.             Printf("\33[1mDClock:\33[0m Background colour set to %ld.\n",DSeg -> BackColour);
  1208.     }
  1209.  
  1210.         /* Set/check alarm status. */
  1211.  
  1212.     if(argv[ARG_ALARM])
  1213.     {
  1214.         if(!Strcmp(argv[ARG_ALARM],"OFF"))
  1215.         {
  1216.             if(!Quiet)
  1217.                 Puts("\33[1mDClock:\33[0m Alarm disabled.");
  1218.  
  1219.             DSeg -> Alarm = FALSE;
  1220.         }
  1221.         else
  1222.         {
  1223.             if(!Strcmp(argv[ARG_ALARM],"ON"))
  1224.             {
  1225.                 if(!Quiet)
  1226.                     Puts("\33[1mDClock:\33[0m Alarm enabled.");
  1227.  
  1228.                 DSeg -> Alarm = TRUE;
  1229.             }
  1230.             else
  1231.             {
  1232.                 if(!Strcmp(argv[ARG_ALARM],"INFO"))
  1233.                     Printf("\33[1mDClock:\33[0m Current alarm time is %02ld:%02ld:%02ld.\n",DSeg -> AlarmHour,DSeg -> AlarmMinute,DSeg -> AlarmSecond);
  1234.                 else
  1235.                     Puts(CLI_Help);
  1236.             }
  1237.         }
  1238.     }
  1239.  
  1240.         /* Adjust alarm time. */
  1241.  
  1242.     if(argv[ARG_ALARMTIME])
  1243.     {
  1244.         char TimeBuff[3];
  1245.         register long i,TheTime;
  1246.  
  1247.         TimeBuff[2] = 0;
  1248.  
  1249.         if(strlen(argv[ARG_ALARMTIME]) != 8)
  1250.         {
  1251.             Puts("\33[1mDClock:\33[0m Alarm time format = HH:MM:SS, example: 09:03:07.");
  1252.             exit(10);
  1253.         }
  1254.  
  1255.         TimeBuff[0] = argv[ARG_ALARMTIME][0];
  1256.         TimeBuff[1] = argv[ARG_ALARMTIME][1];
  1257.  
  1258.         TheTime = Atol(TimeBuff);
  1259.  
  1260.         if(TheTime < 0 || TheTime > 23)
  1261.         {
  1262.             Puts("\33[1mDClock:\33[0m Illegal time value, Hours must be within 0 ... 23.");
  1263.             exit(10);
  1264.         }
  1265.  
  1266.         DSeg -> AlarmHour    = TheTime;
  1267.  
  1268.         TimeBuff[0] = argv[ARG_ALARMTIME][3];
  1269.         TimeBuff[1] = argv[ARG_ALARMTIME][4];
  1270.  
  1271.         TheTime = Atol(TimeBuff);
  1272.  
  1273.         if(TheTime < 0 || TheTime > 59)
  1274.         {
  1275.             Puts("\33[1mDClock:\33[0m Illegal time value, Minutes must be within 0 ... 59.");
  1276.             exit(10);
  1277.         }
  1278.  
  1279.         DSeg -> AlarmMinute    = TheTime;
  1280.  
  1281.         TimeBuff[0] = argv[ARG_ALARMTIME][6];
  1282.         TimeBuff[1] = argv[ARG_ALARMTIME][7];
  1283.  
  1284.         TheTime = Atol(TimeBuff);
  1285.  
  1286.         if(TheTime < 0 || TheTime > 59)
  1287.         {
  1288.             Puts("\33[1mDClock:\33[0m Illegal time value, Seconds must be within 0 ... 59.");
  1289.             exit(10);
  1290.         }
  1291.  
  1292.         DSeg -> AlarmSecond    = TheTime;
  1293.  
  1294.         if(!Quiet)
  1295.             Printf("\33[1mDClock:\33[0m Alarm time set to %02ld:%02ld:%02ld.\n",DSeg -> AlarmHour,DSeg -> AlarmMinute,DSeg -> AlarmSecond);
  1296.     }
  1297.  
  1298.     if(argv[ARG_REFRESH])
  1299.     {
  1300.         CloseWorkBench();
  1301.  
  1302.         if(!Quiet)
  1303.             Puts("\33[1mDClock:\33[0m Main window refreshed.");
  1304.     }
  1305.  
  1306.         /* Set environment variables? */
  1307.  
  1308.     if(argv[ARG_SETENV])
  1309.     {
  1310.         if(!Strcmp(argv[ARG_SETENV],"OFF"))
  1311.         {
  1312.             if(!Quiet)
  1313.                 Puts("\33[1mDClock:\33[0m Environment variables disabled.");
  1314.  
  1315.             DSeg -> SetEnv = FALSE;
  1316.         }
  1317.         else
  1318.         {
  1319.             if(!Strcmp(argv[ARG_SETENV],"ON"))
  1320.             {
  1321.                 if(!Quiet)
  1322.                     Puts("\33[1mDClock:\33[0m Environment variables enabled.");
  1323.  
  1324.                 DSeg -> SetEnv = TRUE;
  1325.             }
  1326.             else
  1327.                 Puts(CLI_Help);
  1328.         }
  1329.     }
  1330. }
  1331.